<template>
    <div>
        <el-tree
                :data="data"
                show-checkbox
                node-key="id"
                highlight-current
                :check-strictly="true"
                :default-checked-keys="checked"
                :props="defaultProps"
                ref="tree">

        </el-tree>
        <el-button style="margin-top: 20px" type="primary" @click="handleSubmit()">确 定</el-button>
    </div>
</template>

<script>

    import Management_anthorityService from '../../../model/mfy/system_user/Management_anthorityService.js'
    var management_anthorityService  = Management_anthorityService.getInstance();
    export default {
        props:['role'],
        data() {
            return {
                data: [],
                checked:[],
                // systemNodeFlag:false,
                defaultProps: {
                    children: 'children',
                    label: 'label'
                },
                role2 : this.role,
            };
        },
        watch:{
            role:function () {
                this.role2=this.role
                this.getRoleAuthority();
                this.getBigMenu();
            }
        },
        created(){
            this.getBigMenu();
            this.getRoleAuthority()
        },
        methods:{
            handleSubmit(){
                const authorityIds = this.$refs.tree.getHalfCheckedKeys()
                const childrenIds = this.$refs.tree.getCheckedKeys()
                childrenIds.forEach(item => authorityIds.push(item))
                var a= {}
                a.myid=this.role;
                a.id =authorityIds.toString()
                management_anthorityService.UpdateAuthority(a).then(()=>{
                    this.$emit("refresh")
                });

            },
            getBigMenu(){
                management_anthorityService.getBigData().then((response)=>{
                    if(this.role2==1){
                        response.data.data[9].disabled=true
                        response.data.data[9].children.forEach(menu => {
                            menu.disabled = true
                            menu.children.forEach(child => child.disabled = true)
                        })
                    }
                    this.data=response.data.data
                });
            },
            getRoleAuthority(){
                management_anthorityService.getRoleAuthority(this.role2).then((response)=>{
                    // this.systemNodeFlag = true
                    this.checked=response.data.data
                });
            },
        }
    };
</script>
